﻿@page "/DataStandard/FormulaTest"
<PageTitle>数据标准配置</PageTitle>
@inherits ComponentBaseDataCenter

<h3>自定义公式配置</h3>

<div class="row g-3 form-inline">
    <div class="col-12 col-sm-6">
        <ul class="list-unstyled">
            <li>公式使用说明</li>
            <li>1.使用公式必须用${开头 }结尾中间的为公式</li>
            <li>
               基础用法:
                <ul>
                    <li>字符串表示: ${'我是字符串'}</li>
                    <li>获取当前时间: ${[Now]}</li>
                    <li>获取传入对象:${[Self]}</li>
                    <li>时间戳转换:${TimeStampToDateStr('1681807204045')}</li>
                    <li>获取今日日期:${Today()}</li>
                    <li>获取昨日日期:${DATEDELTA(Today(),-1)}</li>
                </ul>
            </li>
            <li>
                简单计算:
                <ul>
                    <li>2 * (3 + 5)</li>
                    <li>2 * (2*(2*(2+1)))</li>
                    <li>10 % 3</li>
                    <li>3 > 2 and 1 >(3-2) </li>
                    <li>3 % 2 != 10 % 3</li>
                    <li>if( 34 >= 18, 'majeur', 'mineur')</li>
                </ul>
            </li>
            <li>This may still come in handy in some situations.</li>
        </ul>
    </div>
    <div class="col-12 col-sm-6">
        <Textarea DisplayText="输入公式" rows="12" ShowLabel="true" @bind-Value="@input"> </Textarea>
    </div>
    <div class="col-12">
        <Button Text="执行公式"  OnClick="OnTestAsync"></Button>
    </div>
    <div class="col-12 col-sm-6">
        
    </div>
    <div class="col-12 col-sm-6">
        <Textarea DisplayText="输出结果" rows="12" ShowLabel="true" @bind-Value="@result"> </Textarea>
    </div>
</div>

@code {


    /// <summary>
    /// 输入
    /// </summary>
    private string input = "${'我是字符串'}";

    /// <summary>
    /// 结果
    /// </summary>
    private string result;


    /// <summary>
    /// 执行测试
    /// </summary>
    /// <returns></returns>
    private async Task OnTestAsync()
    {
        try
        {
            Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
            keyValuePairs.Add("a", "3333");
            keyValuePairs.Add("b", "444");

            //var test = input.Formula("我是传入对象");
            var test = input.Formula("我是传入对象",keyValuePairs);
            result = test;
            await Task.CompletedTask;
        }
        catch (Exception ex)
        {
            await base.MessageError(ex.ToString());
        }
    }
}
